#!/bin/bash

echo "🔍 测试 SurveyKing 配置..."

# 检查配置文件是否存在
echo "📁 检查配置文件..."
if [ -f "nginx/conf.d/surveyking.conf" ]; then
    echo "✅ surveyking.conf 存在"
else
    echo "❌ surveyking.conf 不存在"
    exit 1
fi

if [ -f "nginx/nginx.conf" ]; then
    echo "✅ nginx.conf 存在"
else
    echo "❌ nginx.conf 不存在"
    exit 1
fi

# 检查docker-compose配置
echo "🐳 检查Docker配置..."
if [ -f "docker-compose.yml" ]; then
    echo "✅ docker-compose.yml 存在"
else
    echo "❌ docker-compose.yml 不存在"
    exit 1
fi

# 测试nginx配置语法
echo "🔧 测试nginx配置语法..."
docker run --rm -v $(pwd)/nginx/nginx.conf:/etc/nginx/nginx.conf:ro -v $(pwd)/nginx/conf.d:/etc/nginx/conf.d:ro nginx:alpine nginx -t

if [ $? -eq 0 ]; then
    echo "✅ nginx配置语法正确"
else
    echo "❌ nginx配置语法错误"
    exit 1
fi

echo ""
echo "🎯 配置说明："
echo "   1. surveyking.conf 通过 volume 挂载到 nginx 容器"
echo "   2. nginx.conf 中的 'include /etc/nginx/conf.d/*.conf;' 自动加载所有配置"
echo "   3. 用户可以通过以下方式访问："
echo "      - 直接访问: http://云服务器IP:1991"
echo "      - 通过nginx: http://云服务器IP:80"
echo ""
echo "✅ 配置验证完成！"
